/* This file is part of the Crimsoon project
  * Copyright (C) 2009 Eduardo Henrique <eduardohleite@gmail.com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
*/

#include <QStringList>

#include "playlist.h"
#include "track.h"
#include "playlistmodel.h"
#include "util.h"

qint32 PlayListModel::rowCount(const QModelIndex &) const
{
    return playList->count();
}

qint32 PlayListModel::columnCount(const QModelIndex &) const
{
    return 6;
}

QVariant PlayListModel::data(const QModelIndex &index, int role) const
{
    if (!index.isValid())
    {
        return QVariant();
    }

    if (role == Qt::TextAlignmentRole)
    {
        return int(Qt::AlignLeft | Qt::AlignVCenter);
    }
    else if (role == Qt::DisplayRole)
    {
        Track  track = playList->at(index.row());
        switch(index.column())
        {
            case 0:
                return track.getTrack();
            case 1:
                return track.getTitle();
            case 2:
                return track.getArtist();
            case 3:
                return track.getAlbum();
            case 4:
                return calculateLength(track.getLength());
            case 5:
                return track.getFileName();
            default:
                return QVariant();
        }
    }

    return QVariant();
}

QVariant PlayListModel::headerData(int section, Qt::Orientation, int role) const
{
    QStringList headers;

    headers << "" << "Title" << "Artist" << "Album" << "Lenght" << "Path";
    if (role == Qt::DisplayRole)
    {
        return headers[section];
    }

    return QVariant();
}

void PlayListModel::setPlayList(const PlayList *list)
{
    playList = (PlayList *)list;
}

PlayListModel::PlayListModel(QObject *parent)
    : QAbstractTableModel(parent)
{
    playList = new PlayList;
}

PlayListModel::~PlayListModel()
{
    delete playList;
}

